var chai=require('chai');
const assert=chai.assert;
var fs=require('fs');
const sinon=require("sinon");
const { URL } = require("url");
class user{
    constructor(){

    }
    setName(name){
        this.name=name;
    }
    setAge(age){
        this.age=age;
    }
}
var user1=new user();
describe('sinon',function(){
    it("should mock readFile",function(done){
        sinon.stub(fs,'readFile').callsFake(function(path,callback){
            console.log('path:  '+path)
            callback(new Error('read Error'))
        });
        
        fs.readFile('../../src/util/input.txt',function(err,data){
            assert.isNotNull(err);
            done();
        });
        assert(fs.readFile.calledOnce);
        var spy=sinon.spy();
        spy('Hello','world');
        console.log(spy.firstCall.args);
    });
    it("sinon test",()=>{
        var setNameSpy=sinon.spy(user1,'setName');
        var setAgeSpy=sinon.spy(user1,'setAge');
        user1.setAge(18);
        user1.setName("hello word");
      
       
       
        console.log('   执行数量：  '+setNameSpy.callCount);
        console.log('   callAfter：  '+setNameSpy.calledAfter(setAgeSpy));
        setNameSpy.restore();
    });
})